package com.example.contact.navigation

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.ui.platform.LocalConfiguration
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.compose.navArgument
import androidx.navigation.navigation
import com.example.contact.view.ContactDetailScreen
import com.example.contact.view.ContactListScreen
import com.example.contact.view.LayoutConstraints
import com.example.contact.viewmodel.ContactDetailViewModel
import com.example.contact.viewmodel.ContactListViewModel
import com.example.featuresdk.view.*


@ExperimentalFoundationApi
fun NavGraphBuilder.contactNestedNavigationGraph(navHostController: NavHostController, featureKey: String) {

    NavigationController.instance.navController = navHostController

    navigation(startDestination = Screen.ContactList.route, route = featureKey) {

        composable(Screen.ContactList.route) {
            val viewModel: ContactListViewModel = hiltViewModel()
            val uiConstraints = LayoutConstraints.init(LocalConfiguration.current)
            ContactListScreen(viewModel.uiState, uiConstraints)
        }

        composable(Screen.ContactDetail.route,
            arguments = listOf(navArgument("id"){type = NavType.LongType})) {

            val uiConstraints = LayoutConstraints.init(LocalConfiguration.current)
            val viewModel: ContactDetailViewModel = hiltViewModel()

            ContactDetailScreen(viewModel.uiState,viewModel.commands, uiConstraints)
        }
        
        composable(Screen.ContactSetting.route){

            val uiConstraints = LayoutConstraints.init(LocalConfiguration.current)

            FullScreen(uiConstraints) {
                AppHeaderContainer(uiConstraints.appHeaderBarHeightDp) {
                    HeaderBackFeatureEntry{
                        NavigationController.instance.back()
                    }
                    AppHeaderTitle("Contact Setting", uiConstraints.headerWidthDp)
                    FeatureEntryPlaceholder()
                }

//                AppBodyView(bodyHeightDp = {(ScreenConstraints.appBodyHeightDp + ScreenConstraints.appBottomBarHeightDp).dp}) {
//                    Text(text = NavigationController.ContactSetting)
//                }
            }
        }
    }
}